package com.itheima.file;

import java.io.File;
import java.util.HashMap;

public class TongJiFile {
    public static void main(String[] args) {
        HashMap<String,Integer> hm=new HashMap<String,Integer>();
        File f=new File("D:\\itcast");
        jiShu(hm,f);
        System.out.println(hm);
    }

    public static void jiShu( HashMap<String,Integer> hm,File f) {
        File[] files = f.listFiles();

            for (File file : files) {
                if (file.isFile()) {
                    String name = file.getName();
                    String[] split = name.split("\\.");
                    if (split.length == 2) {
                        String s = split[1];
                        if (hm.containsKey(s)) {
                            Integer count = hm.get(s);
                            count++;
                            hm.put(s,count);
                        } else {
                            hm.put(s,1);
                        }
                    }
                } else {
                    jiShu(hm, file);
                }

            }
        }


}
